#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_socorr2_dir.info <<%EOF%
   rsp_socorr2_dir
   ----------
   Molecule:         HeH+
   Wave Function:    SCF
   Test Purpose:     Spin-orbit corrections to spin-spin coupling
                     constants
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_socorr2_dir.mol <<'%EOF%'
INTGRL
Calculation of spin-orbit corrections to spin-spin coupling constants

    2    2  X  Y      0.10E-15  0.10E-15
      2.00    1    2    1    1
He  0.00000             0.00000             -0.7
F   1   1
  2.0       1.0
F   1   1
  1.5       1.0
      1.00    1    1    1
H   0.0                 0.0000000000000      0.7
F   1   1
  1.0       1.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_socorr2_dir.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONSE
.DIRECT
**INTEGRALS
.SPIN-ORBIT
.FC
.PSO
**WAVE FUNCTION
.HF
*SCF INPUT
.DOUBLY OCCUPIED
 1 0 0 0
**RESPONSE
.TRPFLG
*QUADRATIC
.ISPABC
0    1    1
.THCLR
 5.0D-6
.APROP
PSO 001
.APROP
PSO 002
.APROP
PSO 003
.APROP
PSO 004
.APROP
PSO 002
.APROP
PSO 003
.APROP
PSO 004
.APROP
PSO 005
.APROP
PSO 006
.CPROP
FC He001
.CPROP
FC H 002
.CFREQ
 1
 0.0
.BPROP
X SPNORB
.BPROP
X1SPNORB
.BPROP
X2SPNORB
.BFREQ
   1
  0.0
.MAX IT
   50
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_socorr2_dir.check
cat >>rsp_socorr2_dir.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Integral setup
CRIT1=`$GREP "Calculation of one\-electron Hamiltonian integrals\." $log | wc -l`
CRIT2=`$GREP "The following one\-electron property integrals are calculated" $log | wc -l`
CRIT3=`$GREP "\- overlap integrals" $log | wc -l`
CRIT4=`$GREP "\- spatial spin\-orbit integrals" $log | wc -l`
CRIT5=`$GREP "\- Fermi contact integrals" $log | wc -l`
CRIT6=`$GREP "\(Dirac delta function integrals\)" $log | wc -l`
CRIT7=`$GREP "\- paramagnetic spin\-orbit integrals" $log | wc -l`
CRIT8=`$GREP "\(nuclear moment \- electron orbit coupling\)" $log | wc -l`
CRIT9=`$GREP "AO-direct calculation" $log | wc -l`
CRIT10=`$GREP "Integrals for all indirect spin\-spin coupling and/or shielding tensors are calculated\." $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10`
CTRL[1]=10
ERROR[1]="INTEGRAL CALCULATION NOT SET UP CORRECTLY"

# Basis set
CRIT1=`$GREP "He * 1 * 2\.0000 * 4 * 4 * \[1s1p\|1s1p\]" $log | wc -l`
CRIT2=`$GREP "H * 1 * 1\.0000 * 1 * 1 * \[1s\|1s\]" $log | wc -l`
CRIT3=`$GREP "total\: * 2 * 3\.0000 * 5 * 5" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[2]=3
ERROR[2]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 6" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT4=`$GREP "3 * z * (\-0|\-)\.7000000000" $log | wc -l`
CRIT5=`$GREP "4 * x * (0| )\.0000000000" $log | wc -l`
CRIT6=`$GREP "5 * y * (0| )\.0000000000" $log | wc -l`
CRIT7=`$GREP "6 * z * (0| )\.7000000000" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7`
CTRL[3]=7
ERROR[3]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 2 * 2 * 2 * 0" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 3 * 1 * 1 * 0" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="SYMMETRY NOT CORRECT"

# Energy
CRIT1=`$GREP "Final * HF energy\: * \-2\.14691462718[0-9]" $log | wc -l`
TEST[5]=`expr	$CRIT1`
CTRL[5]=1
ERROR[5]="SCF ENERGY NOT CORRECT"

# Response setup
CRIT1=`$GREP "Quadratic Response calculation" $log | wc -l`
CRIT2=`$GREP "First hyperpolarizability calculation \: HYPCAL\= T" $log | wc -l`
CRIT3=`$GREP "Spin of operator A \, ISPINA\= * 0" $log | wc -l`
CRIT4=`$GREP "Spin of operator B \, ISPINB\= * 1" $log | wc -l`
CRIT5=`$GREP "Spin of operator C \, ISPINC\= * 1" $log | wc -l`
CRIT6=`$GREP "1 B\-frequencies * (0| )\.000000(D|E)\+00" $log | wc -l`
CRIT7=`$GREP "1 C\-frequencies * (0| )\.000000(D|E)\+00" $log | wc -l`
CRIT8=`$GREP "2 A operators of symmetry * 2 not included" $log | wc -l`
CRIT9=`$GREP "2 A operators of symmetry * 4 not included" $log | wc -l`
CRIT10=`$GREP "2 A OPERATORS OF SYMMETRY NO\: * 3 AND LABELS\:" $log | wc -l`
CRIT11=`$GREP "3 B OPERATORS OF SYMMETRY NO\: * 3 AND LABELS\:" $log | wc -l`
CRIT12=`$GREP "2 C OPERATORS OF SYMMETRY NO\: * 1 AND LABELS\:" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12`
CTRL[6]=12
ERROR[6]="RESPONSE CALCUALTION NOT SET UP CORRECTLY"

# Quadratic response
CRIT1=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (\-0|\-)\.0004785[0-9]" $log | wc -l`
CRIT2=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (0| )\.0005050[0-9]" $log | wc -l`
CRIT3=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (0| )\.0001464[0-9]" $log | wc -l`
CRIT4=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (\-0|\-)\.0001540[0-9]" $log | wc -l`
CRIT5=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (\-0|\-)\.0003498[0-9]" $log | wc -l`
CRIT6=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (0| )\.0003072[0-9]" $log | wc -l`
CRIT7=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (0| )\.0001044[0-9]" $log | wc -l`
CRIT8=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (\-0|\-)\.0000899[0-9]" $log | wc -l`
CRIT9=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (\-0|\-)\.0001286[0-9]" $log | wc -l`
CRIT10=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (0| )\.0001978[0-9]" $log | wc -l`
CRIT11=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (0| )\.0000420[0-9]" $log | wc -l`
CRIT12=`$GREP "\@ *omega B\, omega C\, QR value \: * (0| )\.00000000 * (0| )\.00000000 * (\-0|\-)\.0000641[0-9]" $log | wc -l`
TEST[7]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12`
CTRL[7]=12
ERROR[7]="QUADRATIC RESPONSE NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
